extends HStateNode

## 玩家空闲状态
## 协调输入处理、射线检测和物品管理

var _input_node:HCharacterInputNode
var _raycast_ability:HAbilityRayCast
var _item_manage_ability:HItemManageAbility
var _player_item_use_ability:HPlayerItemUseAbility

func set_up():
	_input_node = HNodeUtilties.get_node_by_type($"../.." ,HCharacterInputNode)
	_raycast_ability = HNodeUtilties.get_node_by_type($"../../Abilities" ,HAbilityRayCast)
	_item_manage_ability = HNodeUtilties.get_node_by_type($"../../Abilities" ,HItemManageAbility)
	_player_item_use_ability = HNodeUtilties.get_node_by_type($"../../Abilities" ,HPlayerItemUseAbility)
	_input_node.set_focus_mode(true)

func update(delta):
	_input_node.update(delta)
	_raycast_ability.physic_execute()
	
	# 处理交互点击
	if _input_node.interact_click:
		_raycast_ability.execute()
	
	# 处理鼠标滑轮，切换物品
	if _input_node.mouse_wheel_delta != 0.0:
		_item_manage_ability.handle_wheel_input(_input_node.mouse_wheel_delta)
	
	# 处理鼠标左键点击，使用当前物品
	if _input_node.mouse_left_click:
		use_current_item()
	
	_input_node.clear_mouse_input()

## 使用当前选中的物品
func use_current_item():
	if not _player_item_use_ability or not _item_manage_ability:
		print("物品使用或管理能力未初始化")
		return
	
	# 获取玩家实体
	var player_entity = HNodeUtilties.get_node_entity($"../..")
	if not player_entity:
		print("无法找到玩家实体")
		return
	
	# 使用玩家专用的物品使用能力
	_player_item_use_ability.use_current_item(_item_manage_ability, player_entity, _input_node)
